from django.db import models

from utils.BaseModel import BaseModel


# Create your models here.


class Coupons(BaseModel):
    name = models.CharField(max_length=32, verbose_name='优惠券名称')
    desc = models.TextField(verbose_name='优惠券描述')
    start_time = models.DateTimeField(verbose_name='优惠券开始时间')
    end_time = models.DateTimeField(verbose_name='优惠券结束时间')
    num = models.IntegerField(verbose_name='优惠券数量')
    condition = models.DecimalField(max_digits=8, decimal_places=2, verbose_name='优惠券使用条件')
    price = models.DecimalField(max_digits=8, decimal_places=2, verbose_name='优惠券价格')
    selected = models.BooleanField(default=False, verbose_name='是否选中')
    user = models.ForeignKey('user.User', null=True, blank=True, on_delete=models.CASCADE, verbose_name='用户')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'coupons'


class payorder(BaseModel):
    orderno = models.CharField(max_length=32, verbose_name='订单编号')
    name = models.CharField(max_length=50, verbose_name='订单名称')
    price = models.DecimalField(max_digits=8, decimal_places=2, verbose_name='价格')
    payprice = models.DecimalField(max_digits=8, decimal_places=2, verbose_name='实际支付价格')
    status = models.IntegerField(default=0, verbose_name='支付状态')
    doctor = models.ForeignKey('doctor.doctor', on_delete=models.CASCADE, verbose_name='医生')
    patient = models.ForeignKey('doctor.Patient', on_delete=models.CASCADE, verbose_name='患者')
    user = models.ForeignKey('user.User', on_delete=models.CASCADE, verbose_name='用户')
    coupon = models.ForeignKey('Coupons', null=True, blank=True, on_delete=models.CASCADE, verbose_name='优惠券')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'payorder'
